<?php
session_start();
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) 
{
	?>
	<link rel="stylesheet" type="text/css" href="style.css" />
<div id="wrap">

<div id="header">
<h1><a href="#">IAPL</a></h1>
<h2>It`s A Prof`s Life</h2>
</div>

<div id="menu">
<ul>
	<li><a href="index.php">Home</a></li>
	<li><a href="data.php">Data</a></li>
	<li><a href="users.php">Users</a></li>
	<li><a href="settings.php">Settings</a></li>
	<li><a href="logout.php">Logout</a></li>
</ul>
</div>

<div id="content">
<div class="left"> 
<h2>Edit Database</h2>
<?if ($_GET["action"]=="e"){?>
<p class="msg"> You are currently editing an existing entry</p>
<?php }?>
	<form name="myform" action="data.php" method="POST">
	<div align="center">
	<table>
	<tr>
	<td>Select the table you would like to view: </td>
	<td><select name="table_search">
		<option value="1">Administrative Committees</option>
		<!--<option value="2">Degrees</option>-->
		<option value="3">Scholarships</option>
		<option value="4">Employment History</option>
		<!--<option value="5">HQP Guiding Committees</option>
		<option value="6">HQP Students</option>
		<option value="7">Program Comittees</option>
		<option value="8">Publications: Conferences</option>
		<option value="9">Publications: Journals</option>
		<option value="10">Publications: Other</option>
		<option value="11">Research: Funding</option>
		<option value="12">Research: Interests</option>
		<option value="13">Research: Lectures</option>
		<option value="14">Reseacrh: Peer Review</option>
		<option value="15">To Do List</option>
		<option value="16">Teaching: Courses</option>
		<option value="17">Personal Information</option>-->
	</select></td>
	<td><input type="submit" /></td>
	</tr>

	</table>
	</div>
	</form>

</br>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' || isset($_GET['table'])) {

	$con = mysql_connect("db.cs.dal.ca","tameem","B00614969");
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}

	mysql_select_db("tameem", $con);
	
    
	if($_POST['table_search']==1 || $_GET['table']==1)
	{
		if($_GET["action"]=="e")
		{
			$sql="SELECT * FROM AdminCommittees WHERE id=".$_GET['id'];
			$result2 = mysql_query($sql);
			$row = mysql_fetch_array($result2);
		}
		
		$result = mysql_query("SELECT * FROM AdminCommittees");
	?>
		<h3>Administrative Committiees</h3>
		</br>
		<form name="myform" action="<? if ($_GET["action"]!="e"){echo "edit_data.php?action=a&table=1" ;} else {echo "edit_data.php?action=e&table=1&id=".$_GET['id']; } ?>" method="POST">
		<div align="center">
		<table>
		<tr>
		<td>Name: </td>
			<td><input type="text" size="25" id="name" name="name" value="<?php if($_GET["action"]=="e"){ echo $row['name'];}?>"></td>
		<td>Committee Type:  </td>
			<td><input type="text" size="25" id="ct" name="ct" value="<?php if($_GET["action"]=="e"){ echo $row['committeeType'];}?>"></td>
		</tr>
		<tr>
		<td>Role:  </td>
			<td><input type="text" size="25" id="role" name="role" value="<?php if($_GET["action"]=="e"){ echo $row['role'];}?>"></td>
		<td>Start Date:  </td>
			<td><input type="text" size="25" id="sd" name="sd" value="<?php if($_GET["action"]=="e"){ echo $row['start'];}?>"></td>
		</tr>
		<tr>
		<td>End Date:  </td>
			<td><input type="text" size="25" id="ed" name="ed" value="<?php if($_GET["action"]=="e"){ echo $row['end'];}?>"></td>
		<td><input type="hidden" name="table_search" value="1"></td>
		<td><input type="submit" /></td>
		</tr>
		</table>
		</div>
		</form>
		
		</br>
		<div align="center">
		<table id="dtable">
		<tbody>
		<tr>
			<th>Name</th>
			<th>Committee Type</th>
			<th>Role</th>
			<th>Start Date</th>
			<th>End Date</th>
			<th>Edit/Delete</th>
		</tr>
		<?php
		$i=0;
		while($row = mysql_fetch_array($result))
		{
			if($i==0)
			{
			?>
				<tr class="r0">
			<?php
				$i=1;
			}
			else if($i==1)
			{
			?>
				<tr class="r1">
			<?php
				$i=0;
			}
			?>
				<td><?php echo $row['name']?></td>
				<td><?php echo $row['committeeType']?></td>
				<td><?php echo $row['role']?></td>
				<td><?php echo $row['start']?></td>
				<td><?php echo $row['end']?></td>
				<td><a href="data.php?action=e&table=1&id=<?php echo $row['id']?>">Edit</a>/ <a href="edit_data.php?action=d&table=1&id=<?php echo $row['id']?>">Delete</a></td>
			</tr>
		<?php	
		}
		?>
		</tbody>
		</table>
		</div>
	<?php
	}
	else if($_POST['table_search']==3 || $_GET['table']==3)
	{
		if($_GET["action"]=="e")
		{
			$sql="SELECT * FROM EducationScholarships WHERE id=".$_GET['id'];
			$result2 = mysql_query($sql);
			$row = mysql_fetch_array($result2);
		}
		
		$result = mysql_query("SELECT * FROM EducationScholarships");
	?>
		<h3>Scholarships</h3>
		</br>
		<form name="myform" action="<? if ($_GET["action"]!="e"){echo "edit_data.php?action=a&table=3" ;} else {echo "edit_data.php?action=e&table=3&id=".$_GET['id']; } ?>" method="POST">
		<div align="center">
		<table>
		<tr>
		<td>Awarding Group: </td>
			<td><input type="text" size="25" id="ag" name="ag" value="<?php if($_GET["action"]=="e"){ echo $row['AwardingGroup'];}?>"></td>
		<td>Award Name:  </td>
			<td><input type="text" size="25" id="an" name="an" value="<?php if($_GET["action"]=="e"){ echo $row['AwardName'];}?>"></td>
		</tr>
		<tr>
		<td>Start Date:  </td>
			<td><input type="text" size="25" id="sd" name="sd" value="<?php if($_GET["action"]=="e"){ echo $row['start'];}?>"></td>
		<td>End Date:  </td>
			<td><input type="text" size="25" id="ed" name="ed" value="<?php if($_GET["action"]=="e"){ echo $row['end'];}?>"></td>
		</tr>
		<tr>
		<td><input type="hidden" name="table_search" value="3"></td>
		<td><input type="submit" /></td>
		</tr>
		</table>
		</div>
		</form>
		
		</br>
		<div align="center">
		<table id="dtable">
		<tbody>
		<tr>
			<th>Awarding Group</th>
			<th>Award Name</th>
			<th>Start Date</th>
			<th>End Date</th>
			<th>Edit/Delete</th>
		</tr>
		<?php
		$i=0;
		while($row = mysql_fetch_array($result))
		{
			if($i==0)
			{
			?>
				<tr class="r0">
			<?php
				$i=1;
			}
			else if($i==1)
			{
			?>
				<tr class="r1">
			<?php
				$i=0;
			}
			?>
				<td><?php echo $row['AwardingGroup']?></td>
				<td><?php echo $row['AwardName']?></td>
				<td><?php echo $row['start']?></td>
				<td><?php echo $row['end']?></td>
				<td><a href="data.php?action=e&table=3&id=<?php echo $row['id']?>">Edit</a>/ <a href="edit_data.php?action=d&table=3&id=<?php echo $row['id']?>">Delete</a></td>
			</tr>
		<?php	
		}
		?>
		</tbody>
		</table>
		</div>
	<?php
	}
	else if($_POST['table_search']==4 || $_GET['table']==4)
	{
		if($_GET["action"]=="e")
		{
			$sql="SELECT * FROM EmploymentHistory WHERE id=".$_GET['id'];
			$result2 = mysql_query($sql);
			$row = mysql_fetch_array($result2);
		}
		
		$result = mysql_query("SELECT * FROM EmploymentHistory");
	?>
		<h3>Administrative Committiees</h3>
		</br>
		<form name="myform" action="<? if ($_GET["action"]!="e"){echo "edit_data.php?action=a&table=4" ;} else {echo "edit_data.php?action=e&table=4&id=".$_GET['id']; } ?>" method="POST">
		<div align="center">
		<table>
		<tr>
		<td>Job Title:  </td>
			<td><input type="text" size="25" id="jt" name="jt" value="<?php if($_GET["action"]=="e"){ echo $row['jobTitle'];}?>"></td>
		<td>Group Name:  </td>
			<td><input type="text" size="25" id="gn" name="gn" value="<?php if($_GET["action"]=="e"){ echo $row['groupName'];}?>"></td>
		</tr>
		<tr>
		<td>Company:  </td>
			<td><input type="text" size="25" id="comp" name="comp" value="<?php if($_GET["action"]=="e"){ echo $row['company'];}?>"></td>
		<td>Supervisor:  </td>
			<td><input type="text" size="25" id="sv" name="sv" value="<?php if($_GET["action"]=="e"){ echo $row['superVisor'];}?>"></td>
		</tr>
		<tr>
		<td>Start Date:  </td>
			<td><input type="text" size="25" id="sd" name="sd" value="<?php if($_GET["action"]=="e"){ echo $row['start'];}?>"></td>
		<td>End Date:  </td>
			<td><input type="text" size="25" id="ed" name="ed" value="<?php if($_GET["action"]=="e"){ echo $row['end'];}?>"></td>
		</tr>
		<td>Job Description:  </td>
			<td><input type="text" size="25" id="jd" name="jd" value="<?php if($_GET["action"]=="e"){ echo $row['jobDescription'];}?>"></td>
		<tr>
		<td><input type="hidden" name="table_search" value="4"></td>
		<td><input type="submit" /></td>
		</tr>
		</table>
		</div>
		</form>
		
		</br>
		<div align="center">
		<table id="dtable">
		<tbody>
		<tr>
			<th>Job Title</th>
			<th>Group Name</th>
			<th>Company</th>
			<th>Supervisor</th>
			<th>Start Date</th>
			<th>End Date</th>
			<th>Job Description</th>
			<th>Edit/Delete</th>
		</tr>
		<?php
		$i=0;
		while($row = mysql_fetch_array($result))
		{
			if($i==0)
			{
			?>
				<tr class="r0">
			<?php
				$i=1;
			}
			else if($i==1)
			{
			?>
				<tr class="r1">
			<?php
				$i=0;
			}
			?>
				<td><?php echo $row['jobTitle']?></td>
				<td><?php echo $row['groupName']?></td>
				<td><?php echo $row['company']?></td>
				<td><?php echo $row['superVisor']?></td>
				<td><?php echo $row['start']?></td>
				<td><?php echo $row['end']?></td>
				<td><?php echo $row['jobDescription']?></td>
				<td><a href="data.php?action=e&table=4&id=<?php echo $row['id']?>">Edit</a>/ <a href="edit_data.php?action=d&table=4&id=<?php echo $row['id']?>">Delete</a></td>
			</tr>
		<?php	
		}
		?>
		</tbody>
		</table>
		</div>
	<?php
	}
	
	
	mysql_close($con);
}

?>	
</div>


<div style="clear: both;"> </div>

</div>

<div id="bottom"> </div>
<div id="footer">
Designed by <a href="http://www.free-css-templates.com/">Free CSS Templates</a>, Thanks to <a href="http://www.openwebdesign.org/">web design company</a>
</div>

</div>

<?php
}
else
{
	header("location:index.php");
}
?>